﻿@{
    ViewBag.Title = "会员升级";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model JStore.Web.Controllers.Users.ViewModels.UserUpdateModel
<link href="../../Scripts/jquery-validation-engine/css/template.css" rel="stylesheet"
    type="text/css" />
<link href="../../Scripts/jquery-validation-engine/css/validationEngine.jquery.css"
    rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-validation-engine/js/jquery.validationEngine.js"
    type="text/javascript"></script>
<script src="../../Scripts/jquery-validation-engine/js/languages/jquery.validationEngine-zh_CN.js"
    type="text/javascript"></script>
<script type="text/javascript">
    $(function () {

        $("#RealMoney").focus();

        $("#form1").validationEngine();

        $("#btnSubmit").click(function() {
            $("#form1").validationEngine();

            if ($("#form1").validationEngine('validate') && confirm('是否确定各项信息完全正确并提交升级?')) {
                $("#form1").submit();
            }
        });

        loadMoney();

        $("#UserTypeId").change(function () {
            loadMoney();
        });

        function loadMoney() {
            var ddlUserTypeId = $("#UserTypeId");
            var lblJoinMoney = $("#lblJoinMoney");

            lblJoinMoney.html();
            var userTypeId = ddlUserTypeId.val();
            var userName = $("#UserName").val();
            if (userTypeId == null || userTypeId == '')
                return;

            $.ajax({
                url: '@Url.Action("GetCardTypePrice", "Users")',
                data: { userName: userName, userTypeId: userTypeId },
                type: "GET",
                success: function (data) {
                    $("#JoinMoney").val(data);
                    lblJoinMoney.html(data + '元');
                }
            });
        }
    });

    function checkRealMoney() {
        var joinMoney = $("#JoinMoney").val();
        var realMoney = $("#RealMoney").val();
        if (parseFloat(realMoney) > parseFloat(joinMoney)) {
            return "[实消金额]不能大于[所需金额]";
        }
    }
</script>
<div class="right_box_card">
    <ul>
        <li class="right_box_card1"><a href="#">会员升级</a></li>
    </ul>
</div>
@using (Html.BeginForm("Update", "Users", FormMethod.Post, new { @class = "formular", id = "form1" }))
{

    <table class="enter_tab" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr height="40">
            <td class="entry_tab_td1" width="15%">
                会员账号：
            </td>
            <td class="entry_tab_td2 red">
                @Model.UserName
                @Html.HiddenFor(c => c.UserName)
            </td>
        </tr>
        <tr height="40">
            <td class="entry_tab_td1" width="15%">
                升级会员类型：
            </td>
            <td class="entry_tab_td2 red">
                @Html.DropDownListFor(c => c.UserTypeId, ViewData["UserTypeList"] as List<SelectListItem>, new { @class = "validate[required]" })
            </td>
        </tr>
        <tr height="40">
            <td class="entry_tab_td1" width="15%">
                所需金额：
            </td>
            <td class="entry_tab_td2 red">
                @Html.Hidden("JoinMoney")
                <label class="text-input" style="color: red; width: 260px; font-weight: bold" id="lblJoinMoney">
                </label>
            </td>
        </tr>
        <tr height="40">
            <td class="entry_tab_td1" width="15%">
                实消金额：
            </td>
            <td class="entry_tab_td2 red">
                @Html.TextBoxFor(c => c.RealMoney, new { @class = "validate[required,custom[integer],min[1],funcCall[checkRealMoney]]" })
            </td>
        </tr>
        <tr height="40">
            <td class="entry_tab_td1" width="15%">
            </td>
            <td class="entry_tab_td2">
                <input type="button" value="立即升级" id="btnSubmit" class="submit" style="float: left; " />
            </td>
        </tr>
    </table>
}